var e = require("../../../@babel/runtime/helpers/objectSpread2"),
  t = require("../../../@babel/runtime/helpers/regeneratorRuntime"),
  a = require("../../../@babel/runtime/helpers/asyncToGenerator"),
  r = require("../../../store/index"),
  n = require("../../../utils/index"),
  i = n.tools.common.getHeaderHeight,
  s = n.helper.tabCommon,
  c = n.helper.location;

function u(e) {
  return o.apply(this, arguments)
}

function o() {
  return (o = a(t().mark((function e(a) {
    var r, n, i, c;
    return t().wrap((function (e) {
      for (;;) switch (e.prev = e.next) {
        case 0:
          "machinery" === a ? (r = s.getStorageKey(), n = s.getFilterParamsInfo(r), (i = n.type.value) && this.setData({
            pickValue: i
          })) : (c = this.data.userLocationCity) && this.setData({
            pickValue: [c]
          });
        case 1:
        case "end":
          return e.stop()
      }
    }), e, this)
  })))).apply(this, arguments)
}

function l(e, t) {
  return p.apply(this, arguments)
}

function p() {
  return (p = a(t().mark((function e(a, r) {
    return t().wrap((function (e) {
      for (;;) switch (e.prev = e.next) {
        case 0:
          return e.abrupt("return", JSON.stringify(a) !== JSON.stringify(r));
        case 1:
        case "end":
          return e.stop()
      }
    }), e)
  })))).apply(this, arguments)
}
Page({
  useStore: function (e) {
    return {
      userLocationCity: e.storage.userLocationCity
    }
  },
  data: {
    isUpdateStorage: !1,
    mechanicalList: [],
    type: "",
    cityData: [],
    pickValue: [],
    pickHeight: i("8rpx"),
    selectLevel: 2
  },
  onLoad: function (e) {
    this.getTreeList()
    var n = this;
    return a(t().mark((function a() {
      var i, s, o, l, p, m, d, f, y, h, b, k;
      return t().wrap((function (t) {
        for (;;) switch (t.prev = t.next) {
          case 0:
            if (i = e.type, s = void 0 === i ? "machinery" : i, o = e.isUpdateStorage, l = void 0 === o ? 1 : o, p = e.selectValue, m = e.selectLevel, d = e.onlyCity, "machinery" !== s && "city" !== s) {
              t.next = 15;
              break
            }
            if ("city" !== s) {
              t.next = 12;
              break
            }
            return t.next = 5, c.getAreaData();
          case 5:
            return f = t.sent, t.next = 8, c.transAreaData(f);
          case 8:
            y = t.sent, n.setData({
              cityData: d ? f : y
            }), t.next = 14;
            break;
          case 12:
            h = r.store.getState().global.mechanicalClass, 1 === Number(m) ? ((b = h.filter((function (e) {
              return -1 !== e.id
            }))).unshift({
              id: 0,
              name: "全部分类",
              pid: 0
            }), n.setData({
              mechanicalList: b
            })) : n.setData({
              mechanicalList: h
            });
          case 14:
            n.setData({
              type: s,
              isUpdateStorage: Number(l),
              selectLevel: Number(m) || 2
            }), p ? (console.log("selectValue :>> ", p), null != (k = JSON.parse(p)) && k.length && n.setData({
              pickValue: k
            })) : Number(l) && u.call(n, s);
          case 15:
          case "end":
            return t.stop()
        }
      }), a)
    })))()
  },
  getTreeList(){
    $.request["GET/business/excavator/model/tree/list"]().then(res=>{

    })
  },
  onChange: function (n) {
    var i = this;
    return a(t().mark((function a() {
      var c, u, o, p, m, d, f, y, h;
      return t().wrap((function (t) {
        switch (t.prev = t.next) {
          case 0:
            if (null == (c = n.detail.pick) || !c.value) {
              t.next = 30;
              break
            }
            if (!i.data.isUpdateStorage) {
              t.next = 29;
              break
            }
            if ("machinery" !== i.data.type) {
              t.next = 18;
              break
            }
            return u = s.getStorageKey(), o = s.getFilterParamsInfo(u), t.next = 8, l.call(i, c, null == o ? void 0 : o.type);
          case 8:
            if (!(p = t.sent)) {
              t.next = 15;
              break
            }
            return t.next = 12, s.setFilterParamsInfo(u, e(e({}, o), {}, {
              type: c
            }));
          case 12:
            console.log(p),
            $.router.back({
              params: {
                isMultiRoleSelectUpdate: p
              }
            }), t.next = 16;
            break;
          case 15:
            console.log('p');
            $.router.back();
          case 16:
            t.next = 27;
            break;
          case 18:
            if (d = null === (m = c.value) || void 0 === m ? void 0 : m[0]) {
              t.next = 21;
              break
            }
            return t.abrupt("return");
          case 21:
            return f = i.data.userLocationCity, y = e(e({}, d), {}, {
              name: "全国" !== (null == d ? void 0 : d.name) ? null == d ? void 0 : d.name.replace("全", "") : null == d ? void 0 : d.name
            }), t.next = 25, l.call(i, y || {}, f);
          case 25:
            (h = t.sent) ? ((0, r.dispatch)(r.actions.storageActions.setItem({
              key: "userLocationCity",
              value: y || {}
            })), $.router.back({
              params: {
                isMultiRoleSelectUpdate: h
              }
            })) : $.router.back();
          case 27:
            t.next = 30;
            break;
          case 29:
          
           $.router.back({
              params: e(e({}, c), {}, {
                "select-type": i.data.type
              })
            });
          case 30:
          case "end":
            return t.stop()
        }
      }), a)
    })))()
  }
});